package ua.amsoft.brelok.db;

import android.database.sqlite.SQLiteDatabase;
import android.test.AndroidTestCase;

public class DatabaseHelperTest extends AndroidTestCase {
    
    // database name
    public static final String BRELOK_DB_NAME = "brelok";
    
    private DatabaseOpenHelper databaseHelper;
    
    @Override
    protected void setUp() throws Exception {
        super.setUp();
        this.databaseHelper = new DatabaseOpenHelper(this.mContext);
    }
    
    public void testShouldCreateBrelokDatabaseHelperInstance() {
        final DatabaseOpenHelper helper = new DatabaseOpenHelper(this.mContext);
        assertNotNull("BrelokDatabaseHelper should be not null", helper);
        assertEquals(DatabaseHelperTest.BRELOK_DB_NAME, helper.getDatabaseName());
    }
    
    public void testShouldCreateWritableDatabase() {
        final SQLiteDatabase database = this.databaseHelper.getWritableDatabase();
        assertNotNull("database should be not null", database);
        assertTrue("database should be opened", database.isOpen());
        assertFalse("Databse should be writable", database.isReadOnly());
        database.close();
    }
    
    public void testShouldCreateDepartamentUsageReportsTable() {
        final SQLiteDatabase database = this.databaseHelper.getWritableDatabase();
        final String durTable = SQLiteDatabase.findEditTable("DepartamentUsageReports");
        assertEquals("DepartamentUsageReports", durTable);
        database.close();
    }
    
    @Override
    protected void tearDown() throws Exception {
        super.tearDown();
        this.databaseHelper.close();
    }
}
